package com.fatgirl.baseUI.visual
{
	import com.fatgirl.baseUI.IButton;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	
	/**
	 * 按钮基类 
	 * 针对 可视化编辑 基类
	 * @author iceman
	 * 
	 */
	public class VButton extends MovieClip implements IButton
	{
		protected const DEFAULT:int = 1;
		protected const OVER:int = 3;
		protected const DOWN:int = 2;
		protected const ENABLED:int = 4;
		protected const SELECT:int = 2; 
		private var m_selected:Boolean = false;
		public function VButton()
		{
			addEvents();
			this.gotoAndStop(DEFAULT);
		}
		
		public override function get enabled():Boolean
		{
			return super.enabled;
		}
		public override function set enabled(value:Boolean):void
		{
			super.enabled = value;
			if(!value)
			{
				this.gotoAndStop(ENABLED);
				removeEvents();
			}
			else
			{
				this.gotoAndStop(DEFAULT);
				addEvents();
			}
		}
		
		public function get selected():Boolean
		{
			return m_selected;
		}
		public function set selected(_b:Boolean):void
		{
			m_selected = _b;
			if(m_selected)
			{
				removeEvents();
				this.gotoAndStop(SELECT);
			}
			else
			{
				addEvents();
				this.gotoAndStop(DEFAULT);
			}
			
			
		}
		private function addEvents():void
		{
			this.addEventListener(MouseEvent.MOUSE_OVER,overHandler);
			this.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
			this.addEventListener(MouseEvent.MOUSE_OUT,outHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,outHandler);
		}
		private function removeEvents():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER,overHandler);
			this.removeEventListener(MouseEvent.MOUSE_DOWN,downHandler);
			this.removeEventListener(MouseEvent.MOUSE_OUT,outHandler);
			this.removeEventListener(MouseEvent.MOUSE_UP,outHandler);
		}
		private function overHandler(e:MouseEvent):void
		{
			this.gotoAndStop(OVER);
		}
		private function downHandler(e:MouseEvent):void
		{
			this.gotoAndStop(DOWN);
		}
		private function outHandler(e:MouseEvent):void
		{
			this.gotoAndStop(DEFAULT);
		}
	}
}